package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.controlPlanPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.context.annotation.Primary;

import java.util.List;

/**
 * ClassName:controlPlanMapp
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/5/23 16:33
 * @Version 1.0
 */
@Mapper
public interface controlPlanMapp {
    /**
     *查询某一个字段不重复项，并且返回查询回来的数值，作为字符串List传回
     */
    @DS("baodingRussia")
    @Select("select distinct ${fieldName} from controlPlan")
    List<String> OneOneStr(String fieldName);
    /**
     *查询某一个字段不重复项，并且满足另一个字段某一个值，返回查询回来的数值，作为字符串List传回
     */
    @DS("baodingRussia")
    @Select("select distinct ${fieldNameA} from controlPlan where ${fieldNameB} = #{valueToMatch}" )
    List<String> findDistinctBValuesByA(String fieldNameA,String fieldNameB, String valueToMatch);
    /**
     *查询某一个字段不重复项，并且满足另外两个字段的值，返回查询回来的数值，作为字符串List传回
     */
    @DS("baodingRussia")
    @Select("select distinct ${fieldNameA} from controlPlan where ${fieldNameB} = #{valueToMatchB} and ${fieldNameC}=#{valueToMatchC} ORDER BY op asc" )
    List<String> findDistinctBValuesByAandB(String fieldNameA,String fieldNameB,String valueToMatchB,String fieldNameC,String valueToMatchC);
    //点击树形结构，将所有的工序数据筛选出来返回到前端。
    //查找ID是否有
    @DS("baodingRussia")
    @Select("select id from controlPlan where id=#{id}")
    Integer findId(Integer id);

    /*新的控制计划表格用到*/
    //根据三个字段查询所有数据,用模糊查询第一个字段(数据都是字符串类型），并且筛选出的是删除标记位为1的数据
    @DS("baodingRussia")
    @Select("select * from controlPlan_new where " +
            "${firstFieldName} like concat('%',#{firstFieldVal},'%') " +
            "and ${secondFieldName} like concat('%',#{secondFieldVal},'%') " +
            "and ${thirdFieldName}=#{thirdFieldVal} " +
            "and deleteSign=1 " +
            "order by orderNumber ASC")
    List<controlPlanPojo> strFieldThree(String firstFieldName, String firstFieldVal, String secondFieldName, String secondFieldVal, String thirdFieldName, String thirdFieldVal);
    //根据id，查询出对应行的数据
    @DS("baodingRussia")
    @Select("select * from controlPlan_new where deleteSign=1 and id=#{number}")
    controlPlanPojo inquiryById(int number);
    //插入一条数据
    @DS("baodingRussia")
    @Insert("INSERT INTO controlPlan_new " +
            "(processNumber, processNumberEnglish, processNumberRussian, " +
            "device, deviceEnglish, deviceRussian, " +
            "operation, operationEnglish, operationRussian, " +
            "numberOrder, product, productEnglish, " +
            "productRussian, processUse, processUseEnglish, " +
            "processUseRussian, characteristic, specification, " +
            "specificationEnglish, specificationRussian, measure, " +
            "measureEnglish, measureRussian, capacity, " +
            "capacityEnglish, capacityRussian, frequency, " +
            "frequencyEnglish, frequencyRussian, method, " +
            "methodEnglish, methodRussian, department, " +
            "departmentEnglish, departmentRussian, reaction, " +
            "drawing, op, workshop, " +
            "orderNumber, deleteSign, controlTesting, " +
            "UpdateTime, establishTime) " +
            "VALUES (#{processNumber}, #{processNumberEnglish}, #{processNumberRussian}, " +
            "#{device}, #{deviceEnglish}, #{deviceRussian}, " +
            "#{operation}, #{operationEnglish}, #{operationRussian}, " +
            "#{numberOrder}, #{product}, #{productEnglish}, " +
            "#{productRussian}, #{processUse}, #{processUseEnglish}, " +
            "#{processUseRussian}, #{characteristic}, #{specification}, " +
            "#{specificationEnglish}, #{specificationRussian}, #{measure}, " +
            "#{measureEnglish}, #{measureRussian}, #{capacity}, " +
            "#{capacityEnglish}, #{capacityRussian}, #{frequency}, " +
            "#{frequencyEnglish}, #{frequencyRussian}, #{method}, " +
            "#{methodEnglish}, #{methodRussian}, #{department}, " +
            "#{departmentEnglish}, #{departmentRussian}, #{reaction}, " +
            "#{drawing}, #{op}, #{workshop}, " +
            "#{orderNumber}, #{deleteSign}, #{controlTesting}, " +
            "#{UpdateTime}, #{establishTime})")
    void insertOne(controlPlanPojo controlPlan);
    //根据ID，修改一行的值
    @DS("baodingRussia")
    void putById(controlPlanPojo controlPlanPojo);
    //根据id，查询数据
    @DS("baodingRussia")
    @Select("select * from controlPlan_new where workshop like concat('%',#{workshop},'%') and drawing=#{drawing} and op=#{op} and deleteSign=1 ORDER BY orderNumber asc")
    List<controlPlanPojo> controlPlanList(controlPlanPojo controlPlanPojo);
    //根据ID修改“控制计划”标记为的值，传递ID、修改值
    @DS("baodingRussia")
    @Select("update controlPlan_new set controlTesting=1 where id=#{id}")
    void putTestingById(String controlTesting,int id);
    //根据ID，查询一条控制计划的内容
    @DS("baodingRussia")
    @Select("select * from controlPlan_new where id=#{id}")
    controlPlanPojo controlPlanById(Integer id);
}
